const request=require('request');

var wxApp = {
    appID :'wxd42f8d093aae3ed8',
    AppSecret : '92ddcd099086eb3b963314ecab864434'
}

var getOpenid = (code)=>{
    return new Promise((reject,reslove)=>{
        request(`https://api.weixin.qq.com/sns/jscode2session?appid=${wxApp.appID}&secret=${wxApp.AppSecret}&js_code=${code}&grant_type=authorization_code`,(err,res,body)=>{
            body = JSON.parse(body);
            // console.log(body.openid);
            reject(body.openid);
        })
    })
}


module.exports = {
    wxApp,
    getOpenid
}